package com.group12.liuxinpeng.login.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Locale;

@Controller
@RequestMapping("/test")
public class TestController {
    @Secured("ROLE_TEST1")
    @RequestMapping("/test1")
    public String test1(){
        return "test/test1";
    }
    @Secured("ROLE_TEST2")
    @RequestMapping("/test2")
    public String test2(){
        return "test/test2";
    }
    @Resource
    private MessageSource messageSource;
    @RequestMapping("/test3")
    @ResponseBody
    public String test3(){
        HashMap<String,Object> message = new HashMap<>();
        Locale locale = LocaleContextHolder.getLocale();
        String msgStr = messageSource.getMessage("test.nav.tip", null, locale);
        message.put("success", true);
        message.put("msg", msgStr);
        message.put("description", msgStr);
        String rst = JSON.toJSONString(message);
        return rst;
    }
}
